//
//  HHBaseTableHeaderView.m
//  ZHUIKit
//
//  Created by Basic on 2019/9/6.
//

#import "HHBaseTableHeaderView.h"
#import <BCComConfigKit/BCComConfigKit.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wstrict-prototypes"
#import <Masonry/Masonry.h>
#pragma clang diagnostic pop
#import <BCUIKit/UIButton+BCHelper.h>
#import <BCFoundation/BCFoundationUtils.h>

@interface HHBaseTableHeaderView()
@property (nonatomic, strong, readwrite) UIImageView *backgroundImgv;
@property (nonatomic, strong, readwrite) UIButton *selectBtn;
@property (nonatomic, strong, readwrite) UIImageView *headerImgv;
@property (nonatomic, strong, readwrite) UIImageView *iconImgv;
@property (nonatomic, strong, readwrite) UILabel *titleLab;
@property (nonatomic, strong, readwrite) UILabel *detailLab;
@property (nonatomic, strong, readwrite) UILabel *bottomSplitLab;
@property (nonatomic, strong, readwrite) UIButton *arrowBtn;
@end

@implementation HHBaseTableHeaderView
//MARK: - life cycle
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupSubviews];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

//MARK: - 初始化
- (void)setupSubviews {
    if (_titleLab.superview) { return; }
    [self addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.offset(0);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(self);
    }];
}

//MARK: - getter
-(UIImageView *)backgroundImgv {
    if (!_backgroundImgv) {
        _backgroundImgv = [[UIImageView alloc] init];
//        _backgroundImgv.contentMode = UIViewContentModeCenter;
        [self insertSubview:_backgroundImgv atIndex:0];
        [_backgroundImgv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.top.mas_equalTo(0);
            make.right.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
        }];
    }
    return _backgroundImgv;
}
-(UIButton *)selectBtn {
    if (!_selectBtn) {
        _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_selectBtn addTarget:self action:@selector(onSelectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_selectBtn];
        [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.centerY.offset(0);
            make.width.mas_equalTo(40);
            make.height.mas_equalTo(40);
        }];
    }
    return _selectBtn;
}
-(UIImageView *)headerImgv {
    if (!_headerImgv) {
        _headerImgv = [[UIImageView alloc] init];
        [self addSubview:_headerImgv];
        [_headerImgv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
        }];
    }
    return _headerImgv;
}
-(UIImageView *)iconImgv {
    if (!_iconImgv) {
        _iconImgv = [[UIImageView alloc] init];
        [self addSubview:_iconImgv];
        [_iconImgv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(30);
        }];
    }
    return _iconImgv;
}
-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = BCComConfig.shared.bcFont(15);
        _titleLab.textColor = BCComConfig.shared.blackColor;
    }
    return _titleLab;
}
-(UILabel *)detailLab {
    if (!_detailLab) {
        _detailLab = [[UILabel alloc] init];
        _detailLab.font = BCComConfig.shared.bcFont(15);
        _detailLab.textColor = BCComConfig.shared.lightBlackColor;
        [self addSubview:_detailLab];
    }
    return _detailLab;
}
-(UILabel *)bottomSplitLab {
    if (!_bottomSplitLab) {
        _bottomSplitLab = [[UILabel alloc] init];
        _bottomSplitLab.backgroundColor = BCComConfig.shared.splitColor;
        [self addSubview:_bottomSplitLab];
        [_bottomSplitLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.height.mas_equalTo(1);
        }];
    }
    return _bottomSplitLab;
}

//MARK: - event
/// 选择按钮点击事件
- (void)onSelectBtnClick:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (self.selectBtnClickEvent) {
        self.selectBtnClickEvent(sender);
    }
}
@end
